package com.qiumo.gmtool.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qiumo.gmtool.common.RetResult;
import com.qiumo.gmtool.entity.UserEntity;
import com.qiumo.gmtool.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    /**
     * 获取所有用户
     */
    @GetMapping("/list")
    @SaCheckRole("SUPERADMIN")
    public RetResult getAllUser() {
        return RetResult.succ(userService.list());
    }

    /**
     * 获取用户详细信息
     */
    @GetMapping("/info")
    public RetResult info() {
        //获取登陆人UID
        String loginIdAsString = StpUtil.getLoginIdAsString();
        //获取用户信息
        UserEntity user = userService.getOne(new LambdaQueryWrapper<UserEntity>()
            .eq(UserEntity::getUid, loginIdAsString));
        user.setPassword(null);
        return RetResult.succ(user);
    }

}
